package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.mapper.ConcernMapper;
import org.example.pojo.Category;
import org.example.pojo.Result;
import org.example.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/concern")
@Slf4j
public class ConcernController {

    @Autowired
    private ConcernMapper concernMapper;

    @PostMapping()
    public Result<List<Category>> getCategories(@RequestBody Map<String, String> request) {

        String currentUserId = request.get("currentUserId");
        String targetUserId = request.get("targetUserId");


        log.info("{}关注{}为好友",currentUserId,targetUserId);
        try {
            concernMapper.InsertConcern(currentUserId,targetUserId);
            return Result.success();
        }catch (Exception exception){
            concernMapper.deleteBycurrentUserId(currentUserId,targetUserId);
            return Result.success();
//            throw new RuntimeException("已经关注了，已经重复了");
        }
//        finally {
//            return Result.error("重复关注");
//        }


    }
}
